package data
{
	import data.events.DataEvent;
	import data.events.RequestBaseEvent;
	import data.events.SocketBaseEvent;
	
	import flash.events.EventDispatcher;

	/**
	 *数据返回工厂 
	 */	
	public class DataReceive extends EventDispatcher
	{
		public function DataReceive()
		{
			setEvent();
		}
		
		private function setEvent():void
		{
			DataFactory.Instance.socketData.addEventListener(SocketBaseEvent.SOCKET_DATA, socketDataReceive);//socket数据返回事件
			
			DataFactory.Instance.requestData.addEventListener(RequestBaseEvent.REQUEST_DATA, requestDataReceive);//request数据返回事件
			DataFactory.Instance.requestData.addEventListener(RequestBaseEvent.IO_ERROR, requestDataError);//request IO错误事件
			DataFactory.Instance.requestData.addEventListener(RequestBaseEvent.SECURITY_ERROR, requestDataError);//request 安全错误事件
			DataFactory.Instance.requestData.addEventListener(RequestBaseEvent.HTTPSTATUS_ERROR, requestDataError);//request 状态错误事件
		}
		
		/**
		 *Socket数据返回 
		 */		
		private function socketDataReceive(evt:SocketBaseEvent):void
		{
			dispatchEvent(new DataEvent(DataEvent.SOCKET_DATA_RECEIVE, evt.data));
		}
		
		/**
		 *Request数据返回 
		 */		
		private function requestDataReceive(evt:RequestBaseEvent):void
		{
			dispatchEvent(new DataEvent(DataEvent.REQUEST_DATA_RECEIVE, evt.data));
		}
		
		/**
		 *Request事件错误
		 */
		private function requestDataError(evt:RequestBaseEvent):void
		{
			dispatchEvent(new DataEvent(DataEvent.REQUEST_DATA_ERROR, evt.data));
		}
	}
}